package com.bjbn.controller;

import com.bjbn.service.DataMigrationService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.concurrent.CompletableFuture;

/**
 * 数据迁移控制器
 */
@Slf4j
@RestController
@RequestMapping("/api/migration")
@Tag(name = "数据迁移管理", description = "提供数据迁移的API接口")
public class DataMigrationController {

    @Autowired
    private DataMigrationService dataMigrationService;

    /**
     * 开始廊桥信息数据迁移
     */
    @GetMapping("/bridge-info/start")
    @Operation(
            summary = "开始廊桥信息数据迁移",
            description = "启动MySQL到Elasticsearch的廊桥信息数据迁移，采用异步执行方式"
    )
    @ApiResponses(value = {
            @ApiResponse(
                    responseCode = "200",
                    description = "数据迁移任务启动成功",
                    content = @Content(schema = @Schema(implementation = String.class))
            ),
            @ApiResponse(
                    responseCode = "500",
                    description = "服务器内部错误",
                    content = @Content(schema = @Schema(implementation = String.class))
            )
    })
    public CompletableFuture<String> startMigration() {
        log.info("收到开始廊桥信息数据迁移请求");
        return dataMigrationService.startMigration();
    }

    /**
     * 开始廊桥信息历史数据迁移
     */
    @GetMapping("/bridge-info-history/start")
    @Operation(
            summary = "开始廊桥信息历史数据迁移",
            description = "启动MySQL到Elasticsearch的廊桥信息历史数据迁移，采用异步执行方式"
    )
    @ApiResponses(value = {
            @ApiResponse(
                    responseCode = "200",
                    description = "历史数据迁移任务启动成功",
                    content = @Content(schema = @Schema(implementation = String.class))
            ),
            @ApiResponse(
                    responseCode = "500",
                    description = "服务器内部错误",
                    content = @Content(schema = @Schema(implementation = String.class))
            )
    })
    public CompletableFuture<String> startHistoryMigration() {
        log.info("收到开始廊桥信息历史数据迁移请求");
        return dataMigrationService.startHistoryMigration();
    }

    /**
     * 开始廊桥电源信息历史数据迁移
     */
    @GetMapping("/bridge-power-info-history/start")
    @Operation(
            summary = "开始廊桥电源信息历史数据迁移",
            description = "启动MySQL到Elasticsearch的廊桥电源信息历史数据迁移，采用异步执行方式"
    )
    @ApiResponses(value = {
            @ApiResponse(
                    responseCode = "200",
                    description = "电源信息历史数据迁移任务启动成功",
                    content = @Content(schema = @Schema(implementation = String.class))
            ),
            @ApiResponse(
                    responseCode = "500",
                    description = "服务器内部错误",
                    content = @Content(schema = @Schema(implementation = String.class))
            )
    })
    public CompletableFuture<String> startPowerInfoHistoryMigration() {
        log.info("收到开始廊桥电源信息历史数据迁移请求");
        return dataMigrationService.startPowerInfoHistoryMigration();
    }

    /**
     * 开始廊桥飞机空调信息历史数据迁移
     */
    @GetMapping("/bridge-air-conditioning-info-history/start")
    @Operation(
            summary = "开始廊桥飞机空调信息历史数据迁移",
            description = "启动MySQL到Elasticsearch的廊桥飞机空调信息历史数据迁移，采用异步执行方式"
    )
    @ApiResponses(value = {
            @ApiResponse(
                    responseCode = "200",
                    description = "飞机空调信息历史数据迁移任务启动成功",
                    content = @Content(schema = @Schema(implementation = String.class))
            ),
            @ApiResponse(
                    responseCode = "500",
                    description = "服务器内部错误",
                    content = @Content(schema = @Schema(implementation = String.class))
            )
    })
    public CompletableFuture<String> startAirConditioningInfoHistoryMigration() {
        log.info("收到开始廊桥飞机空调信息历史数据迁移请求");
        return dataMigrationService.startAirConditioningInfoHistoryMigration();
    }

    /**
     * 获取廊桥信息数据迁移状态
     */
    @GetMapping("/bridge-info/status")
    @Operation(
            summary = "获取廊桥信息数据迁移状态",
            description = "获取当前廊桥信息数据迁移的状态信息"
    )
    @ApiResponses(value = {
            @ApiResponse(
                    responseCode = "200",
                    description = "获取状态成功",
                    content = @Content(schema = @Schema(implementation = String.class))
            )
    })
    public String getMigrationStatus() {
        log.info("获取廊桥信息数据迁移状态");
        return dataMigrationService.getMigrationStatus();
    }

    /**
     * 获取廊桥信息历史数据迁移状态
     */
    @GetMapping("/bridge-info-history/status")
    @Operation(
            summary = "获取廊桥信息历史数据迁移状态",
            description = "获取当前廊桥信息历史数据迁移的状态信息"
    )
    @ApiResponses(value = {
            @ApiResponse(
                    responseCode = "200",
                    description = "获取状态成功",
                    content = @Content(schema = @Schema(implementation = String.class))
            )
    })
    public String getHistoryMigrationStatus() {
        log.info("获取廊桥信息历史数据迁移状态");
        return dataMigrationService.getHistoryMigrationStatus();
    }

    /**
     * 获取廊桥电源信息历史数据迁移状态
     */
    @GetMapping("/bridge-power-info-history/status")
    @Operation(
            summary = "获取廊桥电源信息历史数据迁移状态",
            description = "获取当前廊桥电源信息历史数据迁移的状态信息"
    )
    @ApiResponses(value = {
            @ApiResponse(
                    responseCode = "200",
                    description = "获取状态成功",
                    content = @Content(schema = @Schema(implementation = String.class))
            )
    })
    public String getPowerInfoHistoryMigrationStatus() {
        log.info("获取廊桥电源信息历史数据迁移状态");
        return dataMigrationService.getPowerInfoHistoryMigrationStatus();
    }

    /**
     * 获取廊桥飞机空调信息历史数据迁移状态
     */
    @GetMapping("/bridge-air-conditioning-info-history/status")
    @Operation(
            summary = "获取廊桥飞机空调信息历史数据迁移状态",
            description = "获取当前廊桥飞机空调信息历史数据迁移的状态信息"
    )
    @ApiResponses(value = {
            @ApiResponse(
                    responseCode = "200",
                    description = "获取状态成功",
                    content = @Content(schema = @Schema(implementation = String.class))
            )
    })
    public String getAirConditioningInfoHistoryMigrationStatus() {
        log.info("获取廊桥飞机空调信息历史数据迁移状态");
        return dataMigrationService.getAirConditioningInfoHistoryMigrationStatus();
    }

    /**
     * 健康检查
     */
    @GetMapping("/health")
    @Operation(
            summary = "健康检查",
            description = "检查数据迁移服务的健康状态"
    )
    @ApiResponses(value = {
            @ApiResponse(
                    responseCode = "200",
                    description = "服务正常",
                    content = @Content(schema = @Schema(implementation = String.class))
            )
    })
    public String health() {
        log.info("数据迁移服务健康检查");
        return "数据迁移服务运行正常";
    }
}
